<?php

class m_form_actions_block_InboxSettingsAction extends m_backoffice_extends_FormModal
{
	public function execute()
	{
		$doc = $this->getDocumentFromRequest();

        $this->setModalParameters();

        $fields = $doc->getListFields();

        /* @var $doc m_form_documents_Structure */

        if($this->isFormSubmit())
        {
            $formValues = $this->getFormValues('form');

            foreach($fields as $k => $field)
            {
                $fields[$k]['visible'] = true;
                
                if(!isset($formValues[$field['name']]))
                {
                    $fields[$k]['visible'] = false;
                }
            }

            $doc->setListConfig(serialize($fields))->save();

            $this->closeModalAndRefresh();
        }

        $this->addToModel('settings', $fields);

		$this->setView('success');
	}	
}